package main.java.indi.zyj.hot100;

import main.java.indi.zyj.hot100.base.TreeNode;

public class _35_diameterOfBinaryTree {


    int ans;


    public int diameterOfBinaryTree(TreeNode root) {
        ans = 1;
        depth(root);
        return ans - 1;
    }
    public int depth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = depth(root.left);
        int right = depth(root.right);

        ans =  Math.max(left + right + 1, ans);

        return Math.max(left, right) + 1;
    }
}
